<?php
include ("includes/header.php");
include ("includes/connection.php");
include ("includes/login.php");
include ("includes/iniciaSessio.php");
?>

<body >
	<?php
	include ("includes/contentHeader.php");
	?>
	<!--contingut 1-->
	<section class="container">
		<!--fons gris-->
		<div class="hero-unit" >
			<h2>Els Meus Viatges</h2>
			<?php
				//'recorregut.idProvinciaInicial' in 'on clause'
				$alias=$_SESSION["username"];
$sql = "select recorregut.*, ruta.adresaOrigen, ruta.adresaFinal, usuari.alias, usuari.foto from(recorregut join usuari on recorregut.idUsuari=usuari.idUsuari) join ruta on recorregut.idRuta=ruta.idRuta where usuari.alias='$alias' order by recorregut.idRuta desc";

$result = mysql_query($sql, $conexion) or die(mysql_error());
while ($row = mysql_fetch_array($result)) {
$idRecorregutTotal = $row['idRecorregut'];

			?>
			<table border="6" style="width: 65%; height: 100px";>
				<tr bgcolor="<?php
				if ($row['idTipusUsuari'] == 'CND') {
					echo "#33CCFF";
				}
				if ($row['idTipusUsuari'] == 'PSG') {
					echo "#00CC66";
				}
				?>">
					<th rowspan="2"><img src="<?php echo $row['foto'];?>" alt='foto' height='100' width='100'/></th>
					<th><?php echo $row['alias'];?></th>
					<th><?php if ($row['data'] != '0000-00-00')
						{
							echo $row['data'];
						}
						if ($row['dl'] == '1' and $row['data'] == '0000-00-00') {
							echo "<img src='images/lunes_si.png' width='25' height='25'/>";
						}
						if ($row['dl'] == '0' and $row['data'] == '0000-00-00') {
							echo "<img src='images/lunes.png' width='25' height='25'/>";
						}
						if ($row['dt'] == '1' and $row['data'] == '0000-00-00') {
							echo "<img src='images/martes_si.png' width='25' height='25'/>";
						}
						if ($row['dt'] == '0' and $row['data'] == '0000-00-00') {
							echo "<img src='images/martes.png' width='25' height='25'/>";
						}
						if ($row['dc'] == '1' and $row['data'] == '0000-00-00') {
							echo "<img src='images/miercoles_si.png' width='25' height='25'/>";
						}
						if ($row['dc'] == '0' and $row['data'] == '0000-00-00') {
							echo "<img src='images/miercoles.png' width='25' height='25'/>";
						}
						if ($row['dj'] == '1' and $row['data'] == '0000-00-00') {
							echo "<img src='images/jueves_si.png' width='25' height='25'/>";
						}
						if ($row['dj'] == '0' and $row['data'] == '0000-00-00') {
							echo "<img src='images/jueves.png' width='25' height='25'/>";
						}
						if ($row['dv'] == '1' and $row['data'] == '0000-00-00') {
							echo "<img src='images/viernes_si.png' width='25' height='25'/>";
						}
						if ($row['dv'] == '0' and $row['data'] == '0000-00-00') {
							echo "<img src='images/viernes.png' width='25' height='25'/>";
						}
						if ($row['ds'] == '1' and $row['data'] == '0000-00-00') {
							echo "<img src='images/sabado_si.png' width='25' height='25'/>";
						}
						if ($row['ds'] == '0' and $row['data'] == '0000-00-00') {
							echo "<img src='images/sabado.png' width='25' height='25'/>";
						}
						if ($row['dg'] == '1' and $row['data'] == '0000-00-00') {
							echo "<img src='images/domingo_si.png' width='25' height='25'/>";
						}
						if ($row['dg'] == '0' and $row['data'] == '0000-00-00') {
							echo "<img src='images/domingo.png' width='25' height='25'/>";
						} ?></th>
				</tr>
				<tr>
					<td><a href="oferta_ruta.php?id=<?=$row['idRuta'] ?>"><?php echo $row['adresaOrigen'];?>  -  <?php echo $row['adresaFinal'];?></td>
					<td>Preu: <?php echo $row['preu'];?>€ Nº Places: <?php echo $row['nPlaces'];?></td>
				</tr>
			</table>
			<?php
			}
			?>
			<div class="offset7">
				<a href="publicar_viatge.php"><img src="images/publicar_viaje.jpg" alt="Publicar viatge" title="Publica el teu viatge" width="250" height="170"</div>
				</div>
				<!-- fi fons gris-->
				</section>
				<!-- fi contingut 1-->
				<!--contingut 2-->
				<section class="container">
				<div class="hero-unit"></div>
				</section>
				<!-- fi contingut 2-->
				<hr>
				<?php
				include ("includes/footer.php");
				?>
